package org.xa3apm.vote.bean;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.xa3apm.vote.hibernate.bean.AccountBean;

@ManagedBean(name = "register")
@SessionScoped
public class RegisterBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3613000215609392424L;
	@EJB
	private AccountBean accountBean;
	private String msg;

	/**
	 * @return the accountBean
	 */
	public final AccountBean getAccountBean() {
		return accountBean;
	}

	/**
	 * @param accountBean
	 *            the accountBean to set
	 */
	public final void setAccountBean(AccountBean accountBean) {
		this.accountBean = accountBean;
	}

	private String userId;
	private String userName;
	private String userPassword;

	/**
	 * @return the userId
	 */
	public final String getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public final void setUserId(String userId) {
		this.userId = userId;
	}

	/**
	 * @return the userName
	 */
	public final String getUserName() {
		return userName;
	}

	/**
	 * @param userName
	 *            the userName to set
	 */
	public final void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the userPassword
	 */
	public final String getUserPassword() {
		return userPassword;
	}

	/**
	 * @param userPassword
	 *            the userPassword to set
	 */
	public final void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	/**
	 * @return the msg
	 */
	public final String getMsg() {
		return msg;
	}

	/**
	 * @param msg
	 *            the msg to set
	 */
	public final void setMsg(String msg) {
		this.msg = msg;
	}

	public RegisterBean() {
		// TODO Auto-generated constructor stub
	}

	public String register() {
		try {
			setMsg(accountBean.register(userId, userName, userPassword));

		} catch (Exception e) {
			setMsg(e.getLocalizedMessage());
		}
		return msg;
	}
}
